<?php
	require_once('../inc/fen_fns.php');
	
	sec_session_start();
	$uid = $_GET['uid'];
	
	if (login_check($mysqli, '>', '50') == true) {

	$query = $_DB->Query("SELECT
						fen_members.id as id,
						fen_members.titr as titr,
						fen_members.name as name,
						fen_members.surname as surname,
						fen_members.username as username,
						fen_department.department_name as department_name,
						fen_members.email as email,
						fen_members.access_level as access_level,
						fen_members.status as status
						from fen_members, fen_department
						WHERE
						fen_members.id = '".$uid."' and fen_members.department_id = fen_department.id
						ORDER BY fen_members.name ASC");
						
	$queryyayin = $_DB->Query("SELECT id from fen_publications where member_id = '$uid'");
	$countyayin = $_DB->GetResultNumber($queryyayin);
	
	$queryyayinlistesiuniversity = $_DB->Query("select yayin_sayisi from (SELECT member_id, IFNULL(SUM(yayin_tipi = 'Makale' || yayin_tipi = 'Kitap bölümü' || yayin_tipi = 'Kitap'), 0) AS yayin_sayisi FROM `fen_publications` GROUP BY member_id ORDER BY yayin_sayisi DESC) AS T1 GROUP BY yayin_sayisi ORDER BY yayin_sayisi DESC");
	$countyayinlistesiuniversity = $_DB->GetResultNumber($queryyayinlistesiuniversity);
	
	$queryyayinlistesifaculty = $_DB->Query("select yayin_sayisi from (SELECT member_id, IFNULL(SUM(yayin_tipi = 'Makale' || yayin_tipi = 'Kitap bölümü' || yayin_tipi = 'Kitap'), 0) AS yayin_sayisi FROM `fen_publications`, `fen_members` WHERE fen_publications.member_id = fen_members.id and fen_members.faculty_id = (select faculty_id from fen_members where id = '".$uid."') GROUP BY member_id ORDER BY yayin_sayisi DESC) AS T1 GROUP BY yayin_sayisi ORDER BY yayin_sayisi DESC");
	$countyayinlistesifaculty = $_DB->GetResultNumber($queryyayinlistesifaculty);
	
	$universitylist = array();
	$universitylist[0] = "zero";
	$facultylist = array();
	$facultylist[0] = "zero";
	
	
	for ($i=0; $i<$countyayinlistesiuniversity; $i++) {
	
		$universitylist[] = $_DB->GetResultValue($queryyayinlistesiuniversity, $i, "yayin_sayisi");
			
	}
	
	$universitylist[] = "0";
	
	for ($i=0; $i<$countyayinlistesifaculty; $i++) {
	
		$facultylist[] = $_DB->GetResultValue($queryyayinlistesifaculty, $i, "yayin_sayisi");
	
	}
	
	$facultylist[] = "0";
	
?>

	<div id="user_detailed_div">
	<div id="user_detailed_head_div">
	<p id="user_detailed_name">&nbsp;
<?php 
			
				echo $_DB->GetResultValue($query, "0", "titr")." ".$_DB->GetResultValue($query, "0", "name")." ".$_DB->GetResultValue($query, "0", "surname");
		
?>
</p>
</div>
<p id="puserdetailed">&nbsp;&nbsp;Fakülte sıralaması: <font color="227da1"><?php echo array_search((string)$countyayin, $facultylist); ?></font></p>
<p id="puserdetailed">&nbsp;&nbsp;Üniversite sıralaması: <font color="227da1"><?php echo array_search((string)$countyayin, $universitylist); ?></font></p>

<div class="summaryTableSmall2detailed">
				<div class="summaryTableSmallTopUser">
					Makale İstatistikleri
				</div>
				<div class="summaryTableSmallMiddle">
					<table cellspacing="0" cellpadding="0" class="summaryTableMakale">
						<tr id="summaryTableMakaleRowTop">
							<td id="summaryTableMakaleTD1">&nbsp; Dergi Sınıf</td>
							<td>SCI</td>
							<td>SCIE</td>
							<td>SSCI</td>
							<td>AHCI</td>
							<td>Alan</td>
							<td>Diğer</td>
							<td bgcolor="#ffeac9"><font color="#555555">Toplam</font></td>
						</tr>
						<tr id="summaryTableMakaleRow1">
							<td id="summaryTableMakaleTD1">&nbsp; A Grubu</td>
<?php 

						$querystata = $_DB->Query("SELECT IFNULL(SUM(indeks_turu = 'SCI'), 0) AS sci, IFNULL(SUM(indeks_turu = 'SCIE'),0) AS scie, IFNULL(SUM(indeks_turu = 'SSCI'),0) AS ssci, IFNULL(SUM(indeks_turu = 'AHCI'),0) AS ahci, IFNULL(SUM(indeks_turu = 'Alan'),0) AS alan, COUNT(indeks_turu) as total FROM fen_publications WHERE member_id = '".$uid."' and yayin_tipi = 'Makale' and sinif = 'A'");
						$querystatb = $_DB->Query("SELECT IFNULL(SUM(indeks_turu = 'SCI'), 0) AS sci, IFNULL(SUM(indeks_turu = 'SCIE'),0) AS scie, IFNULL(SUM(indeks_turu = 'SSCI'),0) AS ssci, IFNULL(SUM(indeks_turu = 'AHCI'),0) AS ahci, IFNULL(SUM(indeks_turu = 'Alan'),0) AS alan, COUNT(indeks_turu) as total FROM fen_publications WHERE member_id = '".$uid."' and yayin_tipi = 'Makale' and sinif = 'B'");
						$querystatc = $_DB->Query("SELECT IFNULL(SUM(indeks_turu = 'SCI'), 0) AS sci, IFNULL(SUM(indeks_turu = 'SCIE'),0) AS scie, IFNULL(SUM(indeks_turu = 'SSCI'),0) AS ssci, IFNULL(SUM(indeks_turu = 'AHCI'),0) AS ahci, IFNULL(SUM(indeks_turu = 'Alan'),0) AS alan, COUNT(indeks_turu) as total FROM fen_publications WHERE member_id = '".$uid."' and yayin_tipi = 'Makale' and sinif = 'C'");
						$querystatd = $_DB->Query("SELECT IFNULL(SUM(indeks_turu = 'SCI'), 0) AS sci, IFNULL(SUM(indeks_turu = 'SCIE'),0) AS scie, IFNULL(SUM(indeks_turu = 'SSCI'),0) AS ssci, IFNULL(SUM(indeks_turu = 'AHCI'),0) AS ahci, IFNULL(SUM(indeks_turu = 'Alan'),0) AS alan, COUNT(indeks_turu) as total FROM fen_publications WHERE member_id = '".$uid."' and yayin_tipi = 'Makale' and sinif = 'D'");
						$querystatdiger = $_DB->Query("SELECT IFNULL(SUM(indeks_turu = 'SCI'), 0) AS sci, IFNULL(SUM(indeks_turu = 'SCIE'),0) AS scie, IFNULL(SUM(indeks_turu = 'SSCI'),0) AS ssci, IFNULL(SUM(indeks_turu = 'AHCI'),0) AS ahci, IFNULL(SUM(indeks_turu = 'Alan'),0) AS alan, IFNULL(SUM(length(indeks_turu) < 1),0) AS diger, COUNT(indeks_turu) as total FROM fen_publications WHERE member_id = '".$uid."' and yayin_tipi = 'Makale' and length(sinif) = 0");
						
?>							
							<td><?php echo $_DB->GetResultValue($querystata, "0", "sci"); ?></td>
							<td><?php echo $_DB->GetResultValue($querystata, "0", "scie"); ?></td>
							<td><?php echo $_DB->GetResultValue($querystata, "0", "ssci"); ?></td>
							<td><?php echo $_DB->GetResultValue($querystata, "0", "ahci"); ?></td>
							<td><?php echo $_DB->GetResultValue($querystata, "0", "alan"); ?></td>
							<td>-</td>
							<td id="summaryTableMakaleTD2"><?php echo $_DB->GetResultValue($querystata, "0", "total"); ?></td>
						</tr>
						<tr id="summaryTableMakaleRow2">
							<td id="summaryTableMakaleTD1">&nbsp; B Grubu</td>
							<td><?php echo $_DB->GetResultValue($querystatb, "0", "sci"); ?></td>
							<td><?php echo $_DB->GetResultValue($querystatb, "0", "scie"); ?></td>
							<td><?php echo $_DB->GetResultValue($querystatb, "0", "ssci"); ?></td>
							<td><?php echo $_DB->GetResultValue($querystatb, "0", "ahci"); ?></td>
							<td><?php echo $_DB->GetResultValue($querystatb, "0", "alan"); ?></td>
							<td>-</td>
							<td id="summaryTableMakaleTD2b"><?php echo $_DB->GetResultValue($querystatb, "0", "total"); ?></td>
						</tr>
						<tr id="summaryTableMakaleRow1">
							<td id="summaryTableMakaleTD1">&nbsp; C Grubu</td>
							<td><?php echo $_DB->GetResultValue($querystatc, "0", "sci"); ?></td>
							<td><?php echo $_DB->GetResultValue($querystatc, "0", "scie"); ?></td>
							<td><?php echo $_DB->GetResultValue($querystatc, "0", "ssci"); ?></td>
							<td><?php echo $_DB->GetResultValue($querystatc, "0", "ahci"); ?></td>
							<td><?php echo $_DB->GetResultValue($querystatc, "0", "alan"); ?></td>
							<td>-</td>
							<td id="summaryTableMakaleTD2"><?php echo $_DB->GetResultValue($querystatc, "0", "total"); ?></td>
						</tr>
						<tr id="summaryTableMakaleRow2">
							<td id="summaryTableMakaleTD1">&nbsp; D Grubu</td>
							<td><?php echo $_DB->GetResultValue($querystatd, "0", "sci"); ?></td>
							<td><?php echo $_DB->GetResultValue($querystatd, "0", "scie"); ?></td>
							<td><?php echo $_DB->GetResultValue($querystatd, "0", "ssci"); ?></td>
							<td><?php echo $_DB->GetResultValue($querystatd, "0", "ahci"); ?></td>
							<td><?php echo $_DB->GetResultValue($querystatd, "0", "alan"); ?></td>
							<td>-</td>
							<td id="summaryTableMakaleTD2b"><?php echo $_DB->GetResultValue($querystatd, "0", "total"); ?></td>
						</tr>
						<tr id="summaryTableMakaleRow1">
							<td id="summaryTableMakaleTD1">&nbsp; Diğer</td>
							<td><?php echo $_DB->GetResultValue($querystatdiger, "0", "sci"); ?></td>
							<td><?php echo $_DB->GetResultValue($querystatdiger, "0", "scie"); ?></td>
							<td><?php echo $_DB->GetResultValue($querystatdiger, "0", "ssci"); ?></td>
							<td><?php echo $_DB->GetResultValue($querystatdiger, "0", "ahci"); ?></td>
							<td><?php echo $_DB->GetResultValue($querystatdiger, "0", "alan"); ?></td>
							<td><?php echo $_DB->GetResultValue($querystatdiger, "0", "diger"); ?></td>
							<td id="summaryTableMakaleTD2"><?php echo $_DB->GetResultValue($querystatdiger, "0", "total"); ?></td>
						</tr>
					</table>
				</div>
				<div class="summaryTableSmallBottom2">
				</div>
</div>
<div class="summaryTableSmall2detailed">
				<div class="summaryTableSmallTopUser">
					Yayın İstatistikleri
				</div>
				<div class="summaryTableSmallMiddleYil">
					<table cellspacing="0" cellpadding="0" class="summaryTableMakale">
							<tr id="summaryTableMakaleRowTop">
								<td id="summaryTableMakaleTD1">&nbsp; Yıl</td>
								<td>Makale</td>
								<td>Kitap Bölümü</td>
								<td>Kitap</td>
								<td bgcolor="#ffeac9"><font color="#555555">&nbsp;&nbsp;Toplam&nbsp;&nbsp;</font></td>
								<td bgcolor="#ebebeb"><font color="#555555">&nbsp;&nbsp;Değişim&nbsp;&nbsp;</font></td>
							</tr>
	<?php 
							$oncekiyil = 0;
							
							function percent($oncekiyil, $toplam){
								
								if ($oncekiyil == 0 && $toplam == 0) {
									return "0 <img src=\"images/icon-zero.gif\"></img>";
								} else if (($toplam-$oncekiyil) == 0) {
									return "0 <img src=\"images/icon-zero.gif\"></img>";
								} else if ($oncekiyil == 0) {
									return "%".($toplam*100)." <img src=\"images/icon-increase.gif\"></img>";
								} else if ($toplam == 0) {
									return "-%".round(($oncekiyil-$toplam)*100)." <img src=\"images/icon-decrease.gif\"></img>";
								} else {
									if ($toplam > $oncekiyil) {
										return "%".round($toplam/$oncekiyil*100)." <img src=\"images/icon-increase.gif\"></img>";
									} else {
										return "-%".round((100-$toplam/$oncekiyil*100))." <img src=\"images/icon-decrease.gif\"></img>";
									}
								}
									

	
							}
							
							
							for ($i=2009; $i<2015; $i++) {

								$query = $_DB->Query("SELECT IFNULL(SUM(yayin_tipi = 'Makale'), 0) AS makale, IFNULL(SUM(yayin_tipi = 'Kitap Bölümü'),0) AS kitapbolumu, IFNULL(SUM(yayin_tipi = 'Kitap'),0) AS kitap FROM fen_publications WHERE member_id = '".$uid."' and yayin_yili = '".$i."'");
								
								$toplam = $_DB->GetResultValue($query, "0", "makale") + $_DB->GetResultValue($query, "0", "kitapbolumu") + $_DB->GetResultValue($query, "0", "kitap");
								
								$degisim = $toplam - $oncekiyil;

								
?>
								<tr id="summaryTableBolumRow1">
										<td id="summaryTableMakaleDepartmentsTDUserDetailed">&nbsp;&nbsp;<?php echo $i; ?></td>
										<td bgcolor="#fafafa"><?php echo $_DB->GetResultValue($query, "0", "makale"); ?></td>
										<td><?php echo $_DB->GetResultValue($query, "0", "kitapbolumu"); ?></td>
										<td bgcolor="#fafafa"><?php echo $_DB->GetResultValue($query, "0", "kitap"); ?></td>
										<td bgcolor="#fff4d3"><?php echo $toplam; ?></td>
										<td bgcolor="#f5f5f5" align="right" ><font color="#555555"><?php if ($i>2009) { echo percent($oncekiyil, $toplam)."&nbsp;"; } else { echo "0 <img src=\"images/icon-zero.gif\"></img>&nbsp;"; } ; ?></font></td>
								</tr>
<?php 	
								$oncekiyil = $toplam;

							}
	
	
	
								$querymakale = $_DB->Query("SELECT fen_publications.id from fen_publications WHERE fen_publications.member_id = ".$uid." AND fen_publications.yayin_tipi = 'Makale'");
								$countmakale = $_DB->GetResultNumber($querymakale);
									
								$querykitapbolumu = $_DB->Query("SELECT fen_publications.id from fen_publications WHERE fen_publications.member_id = ".$uid." AND fen_publications.yayin_tipi = 'Kitap Bölümü'");
								$countkitapbolumu = $_DB->GetResultNumber($querykitapbolumu);
									
								$querykitap = $_DB->Query("SELECT fen_publications.id from fen_publications WHERE fen_publications.member_id = ".$uid." AND fen_publications.yayin_tipi = 'Kitap'");
								$countkitap = $_DB->GetResultNumber($querykitap);
							
?>						

							<tr id="summaryTableMakaleRowBottom">
								<td id="summaryTableMakaleTD1">&nbsp; Toplam</td>
								<td id="summaryTableMakaleDepartmentsTDorange"><?php echo $countmakale; ?></td>
								<td><?php echo $countkitapbolumu; ?></td>
								<td id="summaryTableMakaleDepartmentsTDorange"><?php  echo $countkitap; ?></td>
								<td bgcolor="#ffeac9"><?php echo $countmakale + $countkitapbolumu + $countkitap; ?></td>
							</tr>
						</table>
						
				</div>
				<div class="summaryTableSmallBottom2">
				</div>
				
				<center>
					<form name="input" action="reports.php?rid=2" method="post">
						<input type="hidden" name="user_id" value="<?php echo $uid; ?>">
						<input type="submit" id="buttonAllPublications" value="Tüm Yayınlarını Listele">
					</form>
				</center>
			</div>				
				
</div>

<?php 

	} else {
		header('Location: ./index.php?error=2');
	}

?>